<%@page import="java.util.List"%>
<%@page import="org.nado.bbs.BBSBoardVO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	request.setCharacterEncoding("UTF-8");
%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>
<head>

<base href="../resources/" />
<meta http-equiv="content-type" content="text/html; charset= UTF-8" />
<title>BBS by nado</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link rel="stylesheet" type="text/css" href="style/style.css" />

<style type="text/css">
table {
	width: 500px;
	border-collapse: collapse;
	text-align: center;
	font-family: 'Trebuchet MS';
}

td,th {
	font-size: 10pt;
	border: 1px solid #ffffff;
	height: 30px;
}

th {
	background-color: #aaaaaa;
	color: #ffffff;
	font-family: Georgia;
}

tr.alt td {
	color: #111111;
	background-color: #dcdcdc;
}
</style>

</head>
<body>
<div id="header">
<%@ include file="../common/board_header.jspf"%>
</div>

<div id="main">
<div id="main_inner" class="fixed">
<div id="primaryContent_2columns">
<div id="columnA_2columns">
	<h3>BBS</h3>
	<p>
	<table>
		<tr>
			<th>No</th>
			<th>Title</th>
			<th>Writer</th>
			<th>RegDate</th>
			<th>Count</th>
		</tr>
		<c:forEach var="BBSList" items="${BBSList}">
			<tr>
			<td>${BBSList.bbs_no}</td>
			<td style="text-align: left">
				<a href="/web/bbs/read?bbs_no=${BBSList.bbs_no}&page_no=${page_no}" style="text-decoration: none"> 
				<c:if test="${BBSList.bbs_depth != '0'}">
					<c:forEach begin="1" end="${BBSList.bbs_depth}">
					<!--					Re: -->
					┗
					</c:forEach>
				</c:if> ${BBSList.bbs_title} (${BBSList.bbs_recnt})
				</a></td>
			<td>${BBSList.bbs_writer}</td>
			<td><c:set var="date" value="${BBSList.bbs_regDate}" /> 
			<fmt:formatDate	value="${date}" pattern="yyyy/MM/dd" /></td>
			<td>${BBSList.bbs_readcnt}</td>
			</tr>
		</c:forEach>
		<tr>
		<td style="text-align: left" colspan="3"><br></br>
			<form action="/web/bbs/search/page_no=${page_no}" method="post">
			<select name="type">
				<option value="bbs_title">제목</option>
				<option value="bbs_content">내용</option>
				<option value="bbs_writer">작성자</option>
			</select>
			<input type="text" name="keyword" size="20" required="required"></input>
			<input type="submit" value="검색"></input>
			</form></td>
			
		<td style="text-align: right" colspan="2">
			<br></br>
			<%
			int initPage = -1;
			int maxPage = -1;
			boolean hasNext = false;
			List<BBSBoardVO> list = (List<BBSBoardVO>) request.getAttribute("BBSList");

			maxPage = (int) Math.ceil(list.get(0).getBbs_totalcnt()/(double)10); 
			initPage = (int) (Math.ceil(maxPage/(double)10) *10) -9;
		
			System.out.println("maxPage: " + maxPage);
			System.out.println("initPage: " + initPage);
			
			if(maxPage != 1 /* && (maxPage % 10 == 1) */){
				hasNext = true;
				System.out.println("hasNext: "+hasNext);
 				maxPage = maxPage - 1;
 				System.out.println("-1을 했을 경우에 나오는 maxPage값 : "+maxPage);
 				initPage = maxPage - 9;
 				System.out.println("-1을 했을 경우에 나오는 initPage값 : "+initPage);
			}
			if(initPage != 1){
				%>
				<a href="/bbs/list?page_no=<%=initPage - 1 %>"> < </a>
				<%
			}
			for(int i = initPage; i <= maxPage; i++){
				%>
				<a href="/bbs/list?page_no=<%=i %>">[<%=i %>] </a>
				<%
				if(hasNext == true){
				%>
				<a href="/bbs/list?page_no=<%=maxPage + 1 %>"> > </a>
				<%
				}
			}
// 			int size = (Integer) session.getAttribute("BBSListSize");
// 			int page_no = (Integer) session.getAttribute("page_no");

// 			double page_size = Math.ceil(Math.ceil(size) / 10);
// 			int pNo = (page_no / 10) * 10;

// 			// 					out.print(size);
// 			// 					out.print(page_size);
// 			// 					out.print(pNo);

// 			for (int i = pNo + 1; i < (pNo + 10); i++) {
// 				if (i > 10) {
// 					out.write("<a href='/web/bbs/list?page_no=" + (pNo - 9)
// 							+ "'>" + "이전" + "</a> ");
// 				}
// 				if (i <= page_size) {
// 					out.write("<a href='/web/bbs/list?page_no=" + i + "'>[" + i
// 							+ "]</a> ");
// 					if (i == (pNo + 9)) {
// 						out.write("<a href='/web/bbs/list?page_no="
// 								+ (pNo + 10) + "'>" + "다음" + "</a> ");
// 						break;
// 					}
// 				}
// 			}
			%>
			<form action="/web/bbs/write" method="post">
			<input type="submit" name="write" value="글쓰기"></input>
			</form>
		</td>
		</tr>
	</table>
	</p>
</div>
</div>
</div>
</div>
<div id="aside">
<%@include file="../common/sider.jspf"%>
</div>
<div id="footer" class="fixed">
<%@include file="../common/footer.jspf"%>
</div>
</body>
</html>